23. HAVING

Often there is confusion about the difference between WHERE and HAVING. Select all the statements that are true regarding HAVING and WHERE statements.

SOLUTION:
  • **WHERE** subsets the returned data based on a logical condition.
  • **WHERE** appears after the **FROM**, **JOIN**, and **ON** clauses, but before **GROUP BY**.
  • **HAVING** appears after the **GROUP BY** clause, but before the **ORDER BY** clause.
  • **HAVING** is like **WHERE**, but it works on logical statements involving aggregations.

Questions: HAVING

Use the SQL environment below to assist with answering the following questions. Whether you get stuck or you just want to double check your solutions, my answers can be found at the top of the next concept.

  1. How many of the sales reps have more than 5 accounts that they manage?

  2. How many accounts have more than 20 orders?

  3. Which account has the most orders?

  4. Which accounts spent more than 30,000 usd total across all orders?

  5. Which accounts spent less than 1,000 usd total across all orders?

  6. Which account has spent the most with us?

  7. Which account has spent the least with us?

  8. Which accounts used facebook as a channel to contact customers more than 6 times?

  9. Which account used facebook most as a channel?

  10. Which channel was most frequently used by most accounts?

Code

If you need a code on the https://github.com/udacity.